<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>亚马逊- 购物车</title>
<link href="${pageContext.request.contextPath}/css/index.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/adv.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css" />
<script src="${pageContext.request.contextPath}/scripts/jquery-2.1.0.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/scripts/adv.js" type="text/javascript"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/scripts/function.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/scripts/index.js"></script>
<script type="text/javascript" src="scripts/shopping.js"></script>
    <script>

        $(function () {

			shopCartItem();
        })

		function shopCartItem() {
			$.post("${pageContext.request.contextPath}/shopCarts?param=payment",{
				"count":$("#count").val()
			},function (data) {

			},"json");
		}

		 addorgin=999;
         minorigin=999;
		function add1(i){
			var countlist = document.getElementsByClassName("count");

			var t=countlist[i-1];
			var span=document.getElementsByClassName("span_1")[i-1];
			var gotprice = span.innerText;
			var originprice=parseFloat(gotprice)/parseInt(t.value);

			t.value=parseInt(t.value)+1;
			var price =parseFloat(originprice)*(parseInt(t.value));
			// alert(price);
			span.innerText=price+"";
			// alert(span.innerText)
		}

		function min1(i){
			var countlist = document.getElementsByClassName("count");

			var t=countlist[i-1];
			var span=document.getElementsByClassName("span_1")[i-1];
			var gotprice = span.innerText;
			var originprice=parseFloat(gotprice)/parseInt(t.value);
            if(t.value==1){
            	alert("至少为1");
				return;
			}
			t.value=parseInt(t.value)-1;
			var price =parseFloat(originprice)*(parseInt(t.value));
			// alert(price);
			span.innerText=price+"";
			if(parseInt(t.value)<1){
				t.value=1;
			}
			if(parseInt(t.value)>=$("#stock").html()){
				t.value=$("#stock").html();
			}
		}


	</script>
</head>
<body>
<%@ include file="index_top.jsp"  %>

<div id="position" class="wrap">
	您现在的位置：<a href="${pageContext.request.contextPath}/index.jsp">亚马逊</a> &gt; 购物车
</div>
<div class="wrap">
	<div id="shopping">
		<form action="product" method="post">
			<table>
				<tr>
                    <th><input type="checkbox"></th>
					<th>商品名称</th>
					<th>商品单价</th>
					<th>购买数量</th>
					<th>操作</th>
				</tr>
				
				<c:forEach items="${ShopCartList}" var="prol" varStatus="s">
				<!-- 根据用户购物车生成列表 -->
				<tr id="product_id_1">
                    <td><input type="checkbox"></td>
					<td class="thumb"><img style="width: 100px; height: 100px;" src="${prol.img_source}" />${prol.name}<a href=""></a></td>
					<td class="price" id="price_id_1">
						￥<span id="span_1" class="span_1">${prol.price*prol.count}</span>
						<input type="hidden" id="subPrice" value="" name="sumPrice"/>
						<input type="hidden"  value="" name="pId"/>
						<input type="hidden"  value="" name="hpStock" />
					</td>
					<td class="number">
							<c:set var="hcid" value=""></c:set>
							<input type="button" id="minus" onclick="min1(${s.count})" value=" - " width="3px" name="minusButton" />
							<input id="count" type="text" name="number" class="count" value="${prol.count}" maxlength="5"
							size="1"  style="text-align:center; vertical-align:middle" onblur="checkStock(${hcid})"/>
							<input type="button" id="add" onclick="add1(${s.count})"  value=" + " width="2px" name="addButton" />
					</td>
					<td class="delete"><a href="${pageContext.request.contextPath}/shopCarts?param=del&id=${prol.id}">删除</a></td>
				</tr>
				</c:forEach>
			</table>
			<div class="button"><a href="${pageContext.request.contextPath}/shopCarts?param=payment"><input type="button" value="" /></a></div>
		</form>
	</div>
</div>
<div id="footer">
	Copyright &copy; 2018 上海海文 All Rights Reserved.
</div>
</body>
</html>

